import { getUserByPositionApi } from "@/api/common";
import { getListApi as warehouseCodeApi } from "@/api/configCenter/warehouseCode";
import { getTreeChannelApi } from "@/api/configCenter/warehouseEntryChannel";
import { getCustomerSelectList } from "@/api/managementCenter/customerManagement";
import { getAllCompanyApi } from "@/api/managementCenter/departmentPersonnel";
import { reactive } from "vue";
import { TreeSelect } from "ant-design-vue";
const SHOW_CHILD = TreeSelect.SHOW_CHILD;
export const searchItemList: Array<SuperSearch.SearchItem> = [
  {
    type: "input",
    label: "预报号",
    keyName: "preOrderNoList",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  {
    type: "input",
    label: "运单号",
    keyName: "waybillNumList",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  {
    type: "input",
    label: "FBA单号",
    keyName: "fbaNumberList",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "业务员",
    keyName: "bizIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "4", status: 1 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "客户简称",
    keyName: "customerIdList",
    optionsRequest: getCustomerSelectList,
    optReqParams: { isFilterChild: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    attrs: {
      mode: "multiple"
    },
    optConfig: {
      label: "shortName",
      value: "id"
    },
    options: []
  }),
  {
    type: "select",
    label: "制作发票",
    keyName: "makeInvoiceStatus",
    optConfig: {
      label: "label",
      value: "value"
    },
    options: [
      {
        label: "未制作发票",
        value: -1
      },
      {
        label: "已制作发票",
        value: -2
      }
    ]
  },
  {
    type: "select",
    label: "收货类型",
    keyName: "shippingMethod",
    optConfig: {
      label: "label",
      value: "value"
    },
    options: [
      {
        label: "上门取件",
        value: 0
      },
      {
        label: "自送入仓",
        value: 1
      }
    ]
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "收货司机",
    keyName: "driverUserIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "1", status: 1 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  {
    type: "datetimerange",
    label: "下单时间",
    keyName: "orderTimeList"
  },
  {
    type: "datetimerange",
    label: "取货时间",
    keyName: "expectedPickupTimeList"
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "经营单位",
    keyName: "companyIdList",
    optionsRequest: getAllCompanyApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "name",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "cascader",
    label: "渠道",
    keyName: "channelIdList",
    optionsRequest: getTreeChannelApi,
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "label",
      value: "value",
      children: "children"
    },
    attrs: {
      multiple: true,
      showCheckedStrategy: SHOW_CHILD
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "仓库代码",
    keyName: "warehouseCodeList",
    optionsRequest: warehouseCodeApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "warehouseCode",
      value: "warehouseCode"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  {
    type: "select",
    label: "是否推单",
    keyName: "pushOrderSuccess",
    optConfig: {
      label: "name",
      value: "code"
    },
    options: [
      {
        name: "是",
        code: "1"
      },
      {
        name: "否",
        code: "0"
      }
    ]
  }
];

export const tableColumnMap: Base.GeneraDataType<Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem>> = {
  "3": [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50",
      fixed: "left"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "180",
      renderSlot: "waybillNum",
      fixed: "left"
    },
    {
      field: "preOrderNo",
      title: "预报单号",
      minWidth: "140"
    },
    {
      field: "addressType",
      title: "运单类型",
      minWidth: "120",
      renderSlot: "addressType"
    },
    {
      field: "mergeNo",
      title: "合并报关号",
      minWidth: "90"
    },
    {
      field: "pushOrderTag",
      title: "推单失败原因",
      minWidth: "110"
    },
    {
      field: "shortName",
      title: "客户简称",
      minWidth: "120"
    },
    {
      field: "countryRegionName",
      title: "目的地",
      minWidth: "90"
    },
    {
      field: "itemNumber",
      title: "件数",
      minWidth: "80",
      renderSlot: "itemNumber"
    },
    {
      field: "channelName",
      title: "渠道",
      minWidth: "140"
    },
    {
      field: "makeInvoiceStatus",
      title: "制作发票",
      minWidth: "120",
      renderSlot: "makeInvoiceStatus"
    },
    {
      field: "remark",
      title: "客户备注",
      minWidth: "140"
    },
    {
      field: "innerRemark",
      title: "内部备注",
      minWidth: "140"
    },
    {
      field: "productName",
      title: "品名",
      minWidth: "120"
    },
    {
      field: "materialQualityName",
      title: "材质",
      minWidth: "120"
    },
    {
      field: "bizName",
      title: "业务员",
      minWidth: "90"
    },
    {
      field: "followName",
      title: "跟单员",
      minWidth: "90"
    },
    {
      field: "expectedPickupTime",
      title: "期望取件时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "preOrderApplyer",
      title: "下单人",
      minWidth: "90"
    },
    {
      field: "preOrderApplyTime",
      title: "下单时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "shippingMethod",
      title: "收货类型",
      minWidth: "120",
      formatter: ({ cellValue }: any) => {
        if (Number(cellValue) === 0) return "上门取件";
        else if (Number(cellValue) === 1) return "自送入仓";
        else return "-";
      }
    },
    {
      field: "companyName",
      title: "经营单位",
      minWidth: "80"
    },
    {
      field: "driverUserName",
      title: "收货司机",
      minWidth: "90"
    }
  ],
  "4": [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50",
      fixed: "left"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "180",
      renderSlot: "waybillNum",
      fixed: "left"
    },
    {
      field: "preOrderNo",
      title: "预报单号",
      minWidth: "140"
    },
    {
      field: "addressType",
      title: "运单类型",
      minWidth: "120",
      renderSlot: "addressType"
    },
    {
      field: "mergeNo",
      title: "合并报关号",
      minWidth: "90"
    },
    {
      field: "pushOrderTag",
      title: "推单失败原因",
      minWidth: "110"
    },
    {
      field: "shortName",
      title: "客户简称",
      minWidth: "120"
    },
    {
      field: "countryRegionName",
      title: "目的地",
      minWidth: "90"
    },
    {
      field: "itemNumber",
      title: "件数",
      minWidth: "80",
      renderSlot: "itemNumber"
    },
    {
      field: "channelName",
      title: "渠道",
      minWidth: "140"
    },
    {
      field: "makeInvoiceStatus",
      title: "制作发票",
      minWidth: "120",
      renderSlot: "makeInvoiceStatus"
    },
    {
      field: "remark",
      title: "客户备注",
      minWidth: "140"
    },
    {
      field: "innerRemark",
      title: "内部备注",
      minWidth: "140"
    },
    {
      field: "productName",
      title: "品名",
      minWidth: "120"
    },
    {
      field: "materialQualityName",
      title: "材质",
      minWidth: "120"
    },
    {
      field: "bizName",
      title: "业务员",
      minWidth: "90"
    },
    {
      field: "followName",
      title: "跟单员",
      minWidth: "90"
    },
    {
      field: "expectedPickupTime",
      title: "期望取件时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "preOrderApplyer",
      title: "下单人",
      minWidth: "90"
    },
    {
      field: "preOrderApplyTime",
      title: "下单时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "shippingMethod",
      title: "收货类型",
      minWidth: "120",
      formatter: ({ cellValue }: any) => {
        if (Number(cellValue) === 0) return "上门取件";
        else if (Number(cellValue) === 1) return "自送入仓";
        else return "-";
      }
    },
    {
      field: "companyName",
      title: "经营单位",
      minWidth: "80"
    },
    {
      field: "driverUserName",
      title: "收货司机",
      minWidth: "90"
    }
  ],
  "-1": [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50",
      fixed: "left"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "180",
      renderSlot: "waybillNum",
      fixed: "left"
    },
    {
      field: "preOrderNo",
      title: "预报单号",
      minWidth: "140"
    },
    {
      field: "addressType",
      title: "运单类型",
      minWidth: "120",
      renderSlot: "addressType"
    },
    {
      field: "mergeNo",
      title: "合并报关号",
      minWidth: "90"
    },
    {
      field: "pushOrderTag",
      title: "推单失败原因",
      minWidth: "110"
    },
    {
      field: "shortName",
      title: "客户简称",
      minWidth: "120"
    },
    {
      field: "countryRegionName",
      title: "目的地",
      minWidth: "90"
    },
    {
      field: "itemNumber",
      title: "件数",
      minWidth: "80",
      renderSlot: "itemNumber"
    },
    {
      field: "channelName",
      title: "渠道",
      minWidth: "140"
    },
    {
      field: "makeInvoiceStatus",
      title: "制作发票",
      minWidth: "120",
      renderSlot: "makeInvoiceStatus"
    },
    {
      field: "remark",
      title: "客户备注",
      minWidth: "140"
    },
    {
      field: "innerRemark",
      title: "内部备注",
      minWidth: "140"
    },
    {
      field: "productName",
      title: "品名",
      minWidth: "120"
    },
    {
      field: "materialQualityName",
      title: "材质",
      minWidth: "120"
    },
    {
      field: "bizName",
      title: "业务员",
      minWidth: "90"
    },
    {
      field: "followName",
      title: "跟单员",
      minWidth: "90"
    },
    {
      field: "expectedPickupTime",
      title: "期望取件时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "preOrderApplyer",
      title: "下单人",
      minWidth: "90"
    },
    {
      field: "preOrderApplyTime",
      title: "下单时间",
      minWidth: "135",
      formatter: "formatDate"
    },
    {
      field: "shippingMethod",
      title: "收货类型",
      minWidth: "120",
      formatter: ({ cellValue }: any) => {
        if (Number(cellValue) === 0) return "上门取件";
        else if (Number(cellValue) === 1) return "自送入仓";
        else return "-";
      }
    },
    {
      field: "companyName",
      title: "经营单位",
      minWidth: "80"
    },
    {
      field: "driverUserName",
      title: "收货司机",
      minWidth: "90"
    }
  ]
};

export const tableColumn: Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem> = [
  {
    type: "checkbox",
    field: "checkbox",
    minWidth: "50",
    fixed: "left"
  },
  {
    field: "waybillNum",
    title: "运单号",
    minWidth: "180",
    renderSlot: "waybillNum",
    fixed: "left"
  },

  {
    field: "preOrderNo",
    title: "预报单号",
    minWidth: "140"
  },
  {
    field: "zipCode",
    title: "邮编",
    minWidth: "90"
  },
  {
    field: "warehouseCode",
    title: "仓库代码",
    minWidth: "90"
  },
  {
    field: "addressType",
    title: "运单类型",
    minWidth: "120",
    renderSlot: "addressType"
  },
  {
    field: "mergeNo",
    title: "合并报关号",
    minWidth: "90"
  },
  {
    field: "pushOrderTag",
    title: "推单失败原因",
    minWidth: "110"
  },
  {
    field: "shortName",
    title: "客户简称",
    minWidth: "120"
  },
  {
    field: "countryRegionName",
    title: "目的地",
    minWidth: "90"
  },
  {
    field: "itemNumber",
    title: "件数",
    minWidth: "80",
    renderSlot: "itemNumber"
  },
  {
    field: "channelName",
    title: "渠道",
    minWidth: "140"
  },
  {
    field: "makeInvoiceStatus",
    title: "制作发票",
    minWidth: "120",
    renderSlot: "makeInvoiceStatus"
  },
  {
    field: "remark",
    title: "客户备注",
    minWidth: "140"
  },
  {
    field: "innerRemark",
    title: "内部备注",
    minWidth: "140"
  },
  {
    field: "productName",
    title: "品名",
    minWidth: "120"
  },
  {
    field: "materialQualityName",
    title: "材质",
    minWidth: "120"
  },
  {
    field: "bizName",
    title: "业务员",
    minWidth: "90"
  },
  {
    field: "followName",
    title: "跟单员",
    minWidth: "90"
  },

  {
    field: "completeAddress",
    title: "取件地址",
    minWidth: "220",
    renderSlot: "completeAddress"
  },
  {
    field: "expectedPickupTime",
    title: "期望取件时间",
    minWidth: "170",
    renderSlot: "expectedPickupTime"
  },
  // {
  //   field: "expectedPickupTime",
  //   title: "期望取件时间",
  //   minWidth: "135",
  //   formatter: "formatDate"
  // },
  {
    field: "preOrderApplyer",
    title: "下单人",
    minWidth: "90"
  },
  {
    field: "preOrderApplyTime",
    title: "下单时间",
    minWidth: "135",
    formatter: "formatDate"
  },
  {
    field: "shippingMethod",
    title: "收货类型",
    minWidth: "120",
    formatter: ({ cellValue }: any) => {
      if (Number(cellValue) === 0) return "上门取件";
      else if (Number(cellValue) === 1) return "自送入仓";
      else return "-";
    }
  },
  {
    field: "companyName",
    title: "经营单位",
    minWidth: "80"
  },
  {
    field: "driverUserName",
    title: "收货司机",
    minWidth: "90"
  }
];
